<?php
/**
 * 领取红包记录
 * Class MeRed
 */
namespace App;
defined('IN_IA') or exit('Access Denied');
use Model\RedRecordMod;

class RedRecord extends Action
{
    private $RedRecord = null;

    private $_red_id = 0;  //红包id

    public function __construct()
    {
        parent::__construct();
        $this->RedRecord = new RedRecordMod();
        $this->getUid();
        if($this->_gpc['red_id']) $this->_red_id = $this->_gpc['red_id'];
    }

    /**
     * 获取一个用户的指定红包的记录
     * @param string red_id 用户id
     */
    public function getUserRecord()
    {
        $_record = $this->RedRecord->findOne(
            array(
                'red_id'=>$this->_red_id,
                'uid'=>$this->_uid
            ),
            array('id','money','time')
        );
        if($_record){
            $_member = $this->uidToInfo($this->_uid);
            $_record['nickname'] = $_member['nickname'];
            $_record['header'] = $_member['avatar'];
            $_record['time'] = date('Y-m-d H:i:s',$_record['time']);
            $this->_result = array('status'=>'success','data'=>$_record);
        }
        $this->result($this->_result);
    }

    /**
     * 通过红包id返回开红包记录
     * @param string red_id 红包id
     * @param array limit 请求下标
     */
    public function getList()
    {
        $_list = $this->RedRecord->findAll(
            array(
                'red_id'=>$this->_red_id,
                'uid >'=>0
            ),
            array(
                'order'=>array('id','desc'),
                'limit'=>$this->_gpc['limit']
            ),
            array('id','money','time','uid')
        );
        if(count($_list) > 0){
            foreach($_list as $_k=>$_v){
                $_member = $this->uidToInfo($_v['uid']);
                $_list[$_k]['nickname'] = $_member['nickname'];
                $_list[$_k]['header'] = $_member['avatar'];
                $_list[$_k]['time'] = date('Y-m-d H:i:s',$_v['time']);
            }
            $this->_result = array('status'=>'success','data'=>$_list);
        }
        $this->result($this->_result);
    }
}
